package com.sharecar.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.android.sharecar.model.ReservationPickRequestMsg;
import com.sharecar.db.DB;

public class ReservationPickMsgService {
	private static ReservationPickMsgService service;

	private ReservationPickMsgService() {
	}

	public static ReservationPickMsgService getInstance() {
		if (null == service) {
			service = new ReservationPickMsgService();
		}
		return service;
	}

	public void addMsg(ReservationPickRequestMsg msg) {
		Connection conn = DB.getConn();
		try {
			conn.setAutoCommit(false);
		} catch (SQLException e1) {
			e1.printStackTrace();
		}

		String sql = "insert into PickRide_ReservationRequests values (null, ?, ?, ?, ?)";
		PreparedStatement pstmt = DB.prepare(conn, sql);
		try {

			pstmt.executeUpdate();
			conn.commit();
		} catch (SQLException e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		} finally {
			try {
				conn.setAutoCommit(true);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			DB.close(pstmt);
			DB.close(conn);
		}
	}
}
